namespace Collaboris.Saf.Tests.Generated
{
    using System.IO;

    using Actions.Entities;
    using Actions.Templating;

    using Engine;
    using Engine.Report;

    using Microsoft.VisualStudio.TestTools.UnitTesting;

    using Support;

    [TestClass]
    public class NVelocityTest
    {
        #region Public Methods

        [TestMethod]
        public void NVelocity_Test()
        {
            var nvelocity = new TestAssistant<NVelocity, NVelocityInfo>(
                TestEnvironment.PublishingSite, "NVelocityTestWeb", "BLANKINTERNET#0");

            nvelocity.FirstEntity.TemplateFile = nvelocity.FirstSupportingFilePath;

            if (File.Exists(nvelocity.FirstEntity.OutputFile))
                File.Delete(nvelocity.FirstEntity.OutputFile);

            using (nvelocity)
            {
                MacroReport doReport = nvelocity.DoMacro();
                
                Assert.IsTrue(File.Exists(nvelocity.FirstEntity.OutputFile));
                Assert.IsTrue(nvelocity.FirstEntity.OutputText.Contains(nvelocity.FirstEntity.Properties["From"].ToString()));
                Assert.IsTrue(nvelocity.FirstEntity.OutputText.Contains(nvelocity.FirstEntity.Properties["To"].ToString()));
                Assert.IsTrue(nvelocity.FirstEntity.OutputText.Contains(nvelocity.FirstEntity.Properties["Subject"].ToString()));
                

            }
        }

        [TestMethod]
        public void NVelocity1_Test()
        {
            SafContext ctx = SafContext.CreateContext();
            string outputFile = @"C:\temp\Collaboris.Saf.Tests\helloworld.txt";
            if (File.Exists(outputFile))
                File.Delete(outputFile);

            ctx.ActionProperties.Add("WorkingDirectory", @"C:\temp\Collaboris.Saf.Tests\");
            IMacro macro = MacroEngine.Create(DynamicTestFileLocations.GetNVelocityMacroLoc(), ctx);

            MacroReport report = (MacroReport)macro.Do(ctx);
            Assert.IsTrue(File.Exists(outputFile));

            string outputValue = macro.GetDynamicVariable("VelocityOutput") as string;

            Assert.IsTrue(outputValue.Contains("Mark.Jones@noreply.com"));
            Assert.IsTrue(outputValue.Contains("NVelocity Generated Email"));
            Assert.IsTrue(outputValue.Contains("Fred.Flinstone@noreply.com"));
            Assert.IsTrue(outputValue.Contains("Mark.Jones@noreply.com"));
            Assert.IsTrue(outputValue.Contains(@"C:\temp\Collaboris.Saf.Tests\"));

        }

        #endregion
    }
}